package back_0413.lbservice.server;

//import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH;
//import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;

/**
 * Auth: bruce-sha
 * Date: 2015/3/6
 */
public class LBServerInboundHandler/* extends SimpleChannelInboundHandler<HttpRequest> */ {

//    final SimpleRouteMatcher router = RouteMatcherFactory.get();
//
//    public void channelRead0(ChannelHandlerContext ctx, HttpRequest request) throws Exception {
//
//        if (false) {
//            String s = System.currentTimeMillis() + "<br>" + request.toString();
//            ByteBuf content = Unpooled.wrappedBuffer(s.getBytes(Charsets.UTF_8));
//            DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, OK, content);
//            resp.headers().set(CONTENT_TYPE, "text/html;charset=UTF-8");
//            resp.headers().set(CONTENT_LENGTH, content.readableBytes());//must
//            ctx.writeAndFlush(resp);
//            return;
//        }
//
//        final String uri = request.getUri();
//        final QueryStringDecoder query = new QueryStringDecoder(uri);
//        io.netty.handler.codec.http.HttpMethod method = request.getMethod();
//
//        final String path = query.path();
//        HttpMethod httpMethod = HttpMethod.valueOf(method.name().toLowerCase());
//        String acceptType = request.headers().get("accept");
//
//        RouteMatch routeMatch = router.findTargetForRequestedRoute(httpMethod, path, acceptType);
//
//        final DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.OK);
//
//        RouteImpl route = (RouteImpl) routeMatch.getTarget();
//        Object result = route.bath(request, response);
//
//        String resultStr = route.render(result);
//
//        response.content().writeBytes(resultStr.getBytes(Charsets.UTF_8));
//
//        response.headers().set(CONTENT_TYPE, "text/html;charset=UTF-8");
//        response.headers().set(CONTENT_LENGTH, response.content().readableBytes());//must
//
//        ctx.write(response);
//        ctx.writeAndFlush(result);
//    }
//
////    @Override
////    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
////        super.channelReadComplete(ctx);
////        ctx.flush();
////    }
////
////    @Override
////    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
////        ctx.close();
////    }
}